package com.jiayang.hhotel.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jiayang.hhotel.R;
import com.jiayang.hhotel.bean.AccountsListModel;
import com.jiayang.hhotel.bean.ContractListModel;
import com.yanzhenjie.recyclerview.swipe.SwipeMenuAdapter;

import java.util.List;

/**
 * Created by Administrator on 2017/5/26 0016.
 * 账项列表适配器
 */

public class AccountsListAdapter extends SwipeMenuAdapter<AccountsListAdapter.ViewHolder> {

//    private static final int TYPE_ITEM =0; //普通Item View
//    private static final int TYPE_FOOTER = 1; // 底部FootView

    private List<AccountsListModel.PCashierPayListDtosBean> mList;
    private Context t;
    private OnItemClickListener listener;

    public AccountsListAdapter(Context context, List<AccountsListModel.PCashierPayListDtosBean> list,OnItemClickListener listener){
        this.mList=list;
        this.t=context;
        this.listener=listener;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        final AccountsListModel.PCashierPayListDtosBean model=mList.get(position);
        holder.accountName.setText(t.getString(R.string.account)+t.getString(R.string.space)+model.getDescp());
        holder.accountCode.setText(t.getString(R.string.code)+t.getString(R.string.space)+model.getCode());
        holder.bt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(listener!=null){
                    listener.OnItemClick(model);
                }
            }
        });
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    @Override
    public View onCreateContentView(ViewGroup parent, int viewType) {
        return LayoutInflater.from(t).inflate(R.layout.account_list_item, parent, false);
    }

    @Override
    public ViewHolder onCompatCreateViewHolder(View realContentView, int viewType) {
        return new ViewHolder(realContentView);
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        TextView accountName;//账项名称
        TextView accountCode;//账项代码

        LinearLayout bt;//容器点击

        public ViewHolder(View convertView) {
            super(convertView);
            accountName= (TextView) convertView.findViewById(R.id.tv_account_name);
            accountCode= (TextView) convertView.findViewById(R.id.tv_account_code);
            bt= (LinearLayout) convertView.findViewById(R.id.ll_bt);
        }

    }

    public interface OnItemClickListener{
        void OnItemClick(AccountsListModel.PCashierPayListDtosBean model);
    }
}
